﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Application.ProductApp;
using Utility;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace JFWebAPI.Controllers
{
    /// <summary>
    /// 产品API
    /// </summary>
    [Route("api/[controller]")]
    public class ProductController : Controller
    {

        private IProductAppService _productAppService;
        public ProductController(IProductAppService productAppService)
        {
            _productAppService = productAppService;
        }

        /// <summary>
        /// 产品信息新增接口
        /// </summary>
        /// <param name="model">产品JSON</param>
        /// <returns></returns>
        [HttpPost]
        public string Post([FromBody]Domain.Entities.Product model)
        {
            model.Id = 0;//都添加
            model.Createtime = DateTime.Now;
            if (_productAppService.AddOrUpdate(model))
            {
                return ReturnJsonHelp.OutHandlerJson(true, "提交成功！");
            }
            else
            {
                return ReturnJsonHelp.OutHandlerJson(false, "提交失败！");
            }
        }
        

    }
    
}
